package com.jayceebee.budgie.listadpters;

import com.jayceebee.budgie.R;
import com.jayceebee.budgie.db.BudgieDBAdapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class MerchantCursorAdapter extends SimpleCursorAdapter {

	private Cursor c;
    private Context context;
    
	public MerchantCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
		super(context, layout, c, from, to);
		this.c = c;
		this.context = context;
	}
	
	public View getView(int pos, View inView, ViewGroup parent) {
	       View v = inView;
	       if (v == null) {
	            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            v = inflater.inflate(R.layout.merchantrow, null);
	       }
	       this.c.moveToPosition(pos);		
	       TextView tt = (TextView) v.findViewById(R.id.merchantname);
           TextView bt = (TextView) v.findViewById(R.id.merchant_categoryname);
           if (tt != null) {
                 tt.setText(c.getString(c.getColumnIndex(BudgieDBAdapter.COLUMN_VIEW_MERCHANT_NAME)));                            
           }
           if(bt != null){
        	   String categorgName = c.getString(c.getColumnIndex(BudgieDBAdapter.COLUMN_VIEW_CATEGORY_NAME));
        	     if (categorgName!=null) {
        	    	 bt.setText(categorgName);
        	     } else {
        	    	 bt.setText("no category assigned");
        	     }
        	     
                 
           }
	       return(v);
	}
}
